From da2bf8f774ec1dea9cad5ec02a2fbb93869bf178 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Tue, 31 Dec 2013 20:41:41 +0000 Subject: [PATCH] Another wave of leak tweaks. --- gpsbabel/compegps.cc | 15 +++++---------- gpsbabel/garmin_txt.cc | 2 +- gpsbabel/gtrnctr.cc | 14 ++++++-------- gpsbabel/humminbird.cc | 16 +++++++++++++--- gpsbabel/lowranceusr.cc | 12 ++++++------ gpsbabel/lowranceusr4.cc | 10 +++++----- gpsbabel/route.cc | 40 +++------------------------------------- 7 files changed, 39 insertions(+), 70 deletions(-) diff --git a/gpsbabel/compegps.cc b/gpsbabel/compegps.cc index 90b90dabe..cd4e71efd 100644 --- a/gpsbabel/compegps.cc +++ b/gpsbabel/compegps.cc @@ -185,7 +185,7 @@ parse_wpt(char* buff) *cx-- = '\0'; } if (*c != '\0') { - wpt->shortname = xstrdup(c); + wpt->shortname = c; } break; case 2: @@ -213,17 +213,12 @@ parse_wpt(char* buff) wpt->altitude = atof(c); break; case 7: - wpt->description = xstrdup(c); + wpt->description = c; break; default: if (col > 7) { -#if NEW_STRINGS wpt->description += " "; wpt->description += c; -#else - wpt->description = xstrappend(wpt->description, " "); - wpt->description = xstrappend(wpt->description, c); -#endif } } } @@ -340,7 +335,7 @@ parse_track_info(const char* buff, route_head* track) /* "t" */ case 0: break; /* unknown field */ case 1: - track->rte_name = xstrdup(c); + track->rte_name = c; break; case 2: break; /* unknown field */ @@ -369,7 +364,7 @@ parse_rte_info(const char* buff, route_head* route) /* "R" */ case 0: break; /* unknown field (colour?) */ case 1: - route->rte_name = xstrdup(c); + route->rte_name = c; break; case 2: break; /* unknown field */ @@ -526,7 +521,7 @@ write_route_hdr_cb(const route_head* rte) if (name != NULL) { name = csv_stringclean(name, ","); } else { - name = xstrdup(" "); + name = " "; } gbfprintf(fout, "R 16711680,%s,1,-1\n", CSTR(name)); } diff --git a/gpsbabel/garmin_txt.cc b/gpsbabel/garmin_txt.cc index d4507704c..8881654e4 100644 --- a/gpsbabel/garmin_txt.cc +++ b/gpsbabel/garmin_txt.cc @@ -99,7 +99,7 @@ static int header_ct[unknown_header + 1]; /* macros */ #define IS_VALID_ALT(a) (((a) != unknown_alt) && ((a) < GARMIN_UNKNOWN_ALT)) -#define DUPSTR(a) (((a) != NULL) && ((a)[0] != 0)) ? xstrdup((a)) : NULL +#define DUPSTR(a) (((a) != NULL) && ((a)[0] != 0)) ? ((a)) : NULL static char* opt_datum = NULL; static char* opt_dist = NULL; diff --git a/gpsbabel/gtrnctr.cc b/gpsbabel/gtrnctr.cc index a0f75836d..10ba61117 100644 --- a/gpsbabel/gtrnctr.cc +++ b/gpsbabel/gtrnctr.cc @@ -474,7 +474,7 @@ gtc_trk_s(const xg_string unused, const QXmlStreamAttributes* unusedattrs) void gtc_trk_ident(xg_string args, const QXmlStreamAttributes* unused) { - trk_head->rte_name = xstrdup(args); + trk_head->rte_name = args; } void @@ -506,7 +506,7 @@ gtc_trk_pnt_e(xg_string args, const QXmlStreamAttributes* unused) char cbuf[10]; waypoint* wpt_lap_s = waypt_dupe(wpt_tmp); snprintf(cbuf, sizeof(cbuf), "LAP%03d", lap_ct); - wpt_lap_s->shortname = xstrdup(cbuf); + wpt_lap_s->shortname = cbuf; waypt_add(wpt_lap_s); lap_s = 0; } @@ -654,9 +654,7 @@ gtc_wpt_pnt_e(xg_string args, const QXmlStreamAttributes* unused) if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) { /* Add the begin position of a CourseLap as a waypoint. */ - char* cbuf; - xasprintf(&cbuf, "LAP%03d", lap_ct); - wpt_tmp->shortname = cbuf; + wpt_tmp->shortname = QString().sprintf("LAP%03d", lap_ct); waypt_add(wpt_tmp); } else { waypt_free(wpt_tmp); @@ -692,9 +690,9 @@ void gtc_wpt_notes(const QString& args, const QXmlStreamAttributes* unused) void gtc_wpt_ident(xg_string args, const QXmlStreamAttributes* unused) { - wpt_tmp->shortname = xstrdup(args); + wpt_tmp->shortname = args; /* Set also as notes for compatibility with garmin usb format */ - wpt_tmp->notes = xstrdup(args); + wpt_tmp->notes = args; } void @@ -718,7 +716,7 @@ gtc_wpt_icon(xg_string args, const QXmlStreamAttributes* unused) void gtc_wpt_notes(xg_string args, const QXmlStreamAttributes* unused) { - wpt_tmp->description = xstrdup(args); + wpt_tmp->description = args; } #endif diff --git a/gpsbabel/humminbird.cc b/gpsbabel/humminbird.cc index 51d2776d3..08d1ebadc 100644 --- a/gpsbabel/humminbird.cc +++ b/gpsbabel/humminbird.cc @@ -287,7 +287,11 @@ humminbird_read_wpt(gbfile* fin) wpt = waypt_new(); - wpt->shortname = xstrndup(w.name, sizeof(w.name)); + // Could probably find a way to eliminate the alloc/copy. + char *s = xstrndup(w.name, sizeof(w.name)); + wpt->shortname = s; + xfree(s); + wpt->SetCreationTime(w.time); guder = gudermannian_i1924(w.north); @@ -358,7 +362,10 @@ humminbird_read_route(gbfile* fin) if (rte == NULL) { rte = route_head_alloc(); route_add_head(rte); - rte->rte_name = xstrndup(hrte.name, sizeof(hrte.name)); + // TODO: find a way to eliminate the copy. + char *s = xstrndup(hrte.name, sizeof(hrte.name)); + rte->rte_name = s; + xfree(s); /* rte->rte_num = hrte.num + 1; only internal number */ } route_add_wpt(rte, waypt_dupe(wpt)); @@ -419,7 +426,10 @@ humminbird_read_track(gbfile* fin) trk = route_head_alloc(); track_add_head(trk); - trk->rte_name = xstrndup(th.name, sizeof(th.name)); + // TODO: find a way to eliminate the copy. + char *s = xstrndup(th.name, sizeof(th.name)); + trk->rte_name = s; + xfree(s); trk->rte_num = th.trk_num; /* We create one wpt for the info in the header */ diff --git a/gpsbabel/lowranceusr.cc b/gpsbabel/lowranceusr.cc index 2f1e1d1f7..a566caaa4 100644 --- a/gpsbabel/lowranceusr.cc +++ b/gpsbabel/lowranceusr.cc @@ -395,7 +395,7 @@ lowranceusr_parse_waypt(waypoint* wpt_tmp) text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in); if (text_len) { buff[text_len] = '\0'; - wpt_tmp->shortname = xstrdup(buff); + wpt_tmp->shortname = buff; } if (global_opts.debug_level >= 1) @@ -405,7 +405,7 @@ lowranceusr_parse_waypt(waypoint* wpt_tmp) text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in); if (text_len) { buff[text_len] = '\0'; - wpt_tmp->description = xstrdup(buff); + wpt_tmp->description = buff; } /* Time is number of seconds since Jan. 1, 2000 */ waypt_time = gbfgetint32(file_in); @@ -470,7 +470,7 @@ lowranceusr_parse_routes(void) text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in); if (text_len) { buff[text_len] = '\0'; - rte_head->rte_name = xstrdup(buff); + rte_head->rte_name = buff; } /* num Legs */ @@ -520,7 +520,7 @@ lowranceusr_parse_icons(void) wpt_tmp->longitude = lon_mm_to_deg(gbfgetint32(file_in)); wpt_tmp->altitude = 0; snprintf(buff, sizeof(buff), "Icon %d", i+1); - wpt_tmp->shortname = xstrdup(buff); + wpt_tmp->shortname = buff; /* symbol */ wpt_tmp->icon_descr = lowranceusr_find_desc_from_icon_number(gbfgetint32(file_in)); waypt_add(wpt_tmp); @@ -560,7 +560,7 @@ lowranceusr_parse_trails(void) if (text_len) { buff[text_len] = '\0'; - trk_head->rte_name = xstrdup(buff); + trk_head->rte_name = buff; } if (global_opts.debug_level >= 1) { @@ -602,7 +602,7 @@ lowranceusr_parse_trails(void) if (!buff[0] && seg_break && j) { trk_tmp = route_head_alloc(); trk_tmp->rte_num = ++trk_num; - trk_tmp->rte_name = xstrdup(trk_head->rte_name); + trk_tmp->rte_name = trk_head->rte_name; track_add_head(trk_tmp); trk_head = trk_tmp; } diff --git a/gpsbabel/lowranceusr4.cc b/gpsbabel/lowranceusr4.cc index 5b7a2f245..8761b4d5a 100644 --- a/gpsbabel/lowranceusr4.cc +++ b/gpsbabel/lowranceusr4.cc @@ -402,7 +402,7 @@ lowranceusr4_parse_waypoints(void) text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); if (text_len) { buff[text_len] = '\0'; - wpt_tmp->shortname = xstrdup(buff); + wpt_tmp->shortname = buff; } /* Long/Lat */ @@ -427,7 +427,7 @@ lowranceusr4_parse_waypoints(void) text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); if (text_len) { buff[text_len] = '\0'; - wpt_tmp->description = xstrdup(buff); + wpt_tmp->description = buff; } /* Alarm radius; XXX: I'm not sure what the units are here, @@ -544,7 +544,7 @@ lowranceusr4_parse_routes(void) text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); if (text_len) { buff[text_len] = '\0'; - rte_head->rte_name = xstrdup(buff); + rte_head->rte_name = buff; } num_legs = gbfgetint32(file_in); @@ -643,7 +643,7 @@ lowranceusr4_parse_trails(void) text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); if (text_len) { buff[text_len] = '\0'; - trk_head->rte_name = xstrdup(buff); + trk_head->rte_name = buff; } /* Flags, discard for now */ @@ -656,7 +656,7 @@ lowranceusr4_parse_trails(void) text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); if (text_len) { buff[text_len] = '\0'; - trk_head->rte_desc = xstrdup(buff); + trk_head->rte_desc = buff; } /* Creation date/time, discard for now */ diff --git a/gpsbabel/route.cc b/gpsbabel/route.cc index 1788d8fc6..ec348e589 100644 --- a/gpsbabel/route.cc +++ b/gpsbabel/route.cc @@ -77,14 +77,6 @@ route_head_alloc(void) static void any_route_free(route_head* rte) { -#if !NEW_STRINGS - if (rte->rte_name) { - xfree(rte->rte_name); - } - if (rte->rte_desc) { - xfree(rte->rte_desc); - } -#endif waypt_flush(&rte->waypoint_list); if (rte->fs) { fs_chain_destroy(rte->fs); @@ -153,11 +145,7 @@ common_route_by_name(queue* routes, const char* name) QUEUE_FOR_EACH(routes, elem, tmp) { rte = (route_head*) elem; -#if NEW_STRINGS if (rte->rte_name == name) { -#else - if (0 == strcmp(rte->rte_name, name)) { -#endif return rte; } } @@ -185,15 +173,8 @@ any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth, const QStr if (ct) { (*ct)++; } -#if NEW_STRINGS if (synth && wpt->shortname.isEmpty()) { - char *t; - xasprintf(&t, "%s%0*d", CSTRc(namepart), number_digits, *ct); - wpt->shortname = t; -#else - if (synth && !wpt->shortname) { - xasprintf(&wpt->shortname,"%s%0*d", CSTR(namepart), number_digits, *ct); -#endif + wpt->shortname = QString().sprintf("%s%0*d", CSTRc(namepart), number_digits, *ct); wpt->wpt_flags.shortname_is_synthetic = 1; } update_common_traits(wpt); @@ -246,11 +227,7 @@ route_find_waypt_by_name(route_head* rh, const char* name) QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) { waypoint* waypointp = (waypoint*) elem; -#if NEW_STRINGS if (waypointp->shortname == name) { -#else - if (0 == strcmp(waypointp->shortname, name)) { -#endif return waypointp; } } @@ -438,8 +415,8 @@ route_copy(int* dst_count, int* dst_wpt_count, queue** dst, queue* src) route_head* rte_old = (route_head*)elem; rte_new = route_head_alloc(); - rte_new->rte_name = xstrdup(rte_old->rte_name); - rte_new->rte_desc = xstrdup(rte_old->rte_desc); + rte_new->rte_name = rte_old->rte_name; + rte_new->rte_desc = rte_old->rte_desc; rte_new->rte_url = rte_old->rte_url; rte_new->fs = fs_chain_copy(rte_old->fs); rte_new->rte_num = rte_old->rte_num; @@ -601,10 +578,6 @@ void track_recompute(const route_head* trk, computed_trkdata** trkdatap) double tot_hrt = 0.0; int pts_cad = 0; double tot_cad = 0.0; -#if NEW_STRINGS -#else - char tkptname[100]; -#endif computed_trkdata* tdata = (computed_trkdata*)xcalloc(1, sizeof(computed_trkdata)); if (trkdatap) { @@ -707,15 +680,8 @@ void track_recompute(const route_head* trk, computed_trkdata** trkdatap) } } prev = thisw; -#if NEW_STRINGS if (thisw->shortname.isEmpty()) { thisw->shortname = QString("%1-%2").arg(trk->rte_name).arg(tkpt); -#else - if (!thisw->shortname || !thisw->shortname[0]) { - snprintf(tkptname, sizeof(tkptname), "%s-%d", - trk->rte_name ? CSTRc(trk->rte_name) : "" , tkpt); - thisw->shortname = xstrdup(tkptname); -#endif } tkpt++; } -- 2.30.2